<template>
    <div>
    <h1>食谱信息列表显示</h1>
    项目名称<input type="text" v-model="page.name">
    <select v-model="page.types">
             <option value="0">请选择</option>
             <option v-for="s in types" :value="s.typeid" >{{s.typename}}</option>
            </select>
    <input type="button" value="查询" @click="cha">
    <table>
        <thead>
            <tr>
                <td><input type="checkbox"  @change="quan" v-model="sells"></td>
                <td>标题</td>
                <td>图片</td>
                <td>类型</td>
                <td>操作</td>
            </tr>
        </thead>
        <tbody>
            <tr v-for="m in data">
                <td><input type="checkbox" :value="m.sid" v-model="idssing"></td>
                <td>{{m.sname}}</td>
                <td> <img  style="height: 100px; width: 100px;" :src="'https://localhost:7076'+m.simg"></td>
                <td>{{m.typename}}</td>
                <td> 操作 </td>
            </tr>
        </tbody>
    </table>
    </div>
    <input type="button" value="首页" @click="fanye(1)">
    <input type="button" value="上一页" @click="fanye(2)">
    <input type="button" value="下一页" @click="fanye(3)">
    <input type="button" value="尾页" @click="fanye(4)">
    一共{{paga.pcount}}页，一共{{paga.count}}行，每页{{page.size}}行，当前第{{page.index}}页
 <select v-model="page.size" @change="rong">
    <option>3</option>
    <option>4</option>
    <option>5</option>
 </select>
 <input type="text" v-model="page.index">
 <input type="button" value="跳转" @click="tiao">

</template>

<script setup lang="ts">
import axios from 'axios';
import { useRouter } from 'vue-router';
import { ref } from 'vue';
import { onMounted } from 'vue';

const sells=ref(false);
const idssing=ref([0])


const quan=()=>
{
    if(sells.value)
{
    for(var i=0;i<data.value.length;i++)
{
    idssing.value.push(data.value[i].sid);
}
}
else{
    idssing.value=[0];
}
}


const data=ref([{
    
    "sid": 0,
  "sname": "",
  "simg": "",
  "typeid": 0,
  "typename": ""

}])

const types=ref([{

"typeid": 0,
"typename": ""
}])


const getdate=()=>
{
    axios.get("https://localhost:7076/api/type/xia").then(res=>
        {
            types.value=res.data;
        }
    )
}




const rong=()=>
{
    page.value.index=1;
    Getdata();
}

const tiao=()=>
{
    if(page.value.index>=1&&page.value.index<=paga.value.pcount)
{
    Getdata();
}
}


const cha=()=>
{
    page.value.index=1;
    Getdata();
}


const fanye=(vid:any)=>
{
    if(vid==1)
{
    page.value.index=1;
    Getdata();
}
if(vid==2)
{
    if(page.value.index>1)
{
    page.value.index-=1;
    Getdata();
}
}
if(vid==3)
{
    if(page.value.index<paga.value.pcount)
{
    page.value.index+=1;
    Getdata();
}
}
if(vid==4)
{
    page.value.index=paga.value.pcount;
    Getdata();
}


}



const paga=ref({
    count:0,
    pcount:0
})

const page=ref({
    index:1,
    size:3,
    name:"",
    types:null
})

onMounted(()=>
{
    Getdata();
    getdate();
})


const Getdata=()=>
{
    axios.get("https://localhost:7076/api/shipu/fen",{params:page.value}).then(res=>
        {
            data.value=res.data.data;
            paga.value.count=res.data.count;
            paga.value.pcount=Math.ceil(paga.value.count/page.value.size)
        }
    )
}



</script>

<style scoped>

</style>